//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __FAT16_H_
#define __FAT16_H_

typedef UInt16 fat16_t;

class fat16
{
public:
    virtual int fat16_init(class fatfs_sharedata *pSharedata);
    virtual void fat16_sync(void);
    virtual struct clust * fat16_alloc(struct clust *c, struct directory *d);
    virtual int fat16_setlen(struct clust *c, UInt32 newclust);
    virtual int fat16_loadfat(class fatfs_sharedata *pSharedata);
    virtual UInt64 fat16_calcfreespace();
#if defined(_DEBUG)
    void fat16_stat(UInt32 *Fat_secs);
#endif
    fat16();
    virtual ~fat16();

    class fatfs_sharedata *p_Sharedata;
private:
    fat16_t *fat;     /* Our in-core FAT */
    UInt32 fatlen;      /*  ...length */
    UInt8 *dirtymap;  /* Map of sectors with dirty FAT entries */
    UInt32 dirtymapsize; /*  ...size of map */
    UInt32 nxt_clust;   /* Where last cluster search left off */
};

/*-------------------------------------------------------------------------*/
/* FAT flag values for FAT-16                                              */
/*-------------------------------------------------------------------------*/
#define FAT16_RESERVED (0xFFF0)    /* Start of reserved value range */
#define FAT16_DEFECT (0xFFF7)    /* Cluster w. defective block */
#define FAT16_EOF (0xFFF8)    /* Start of EOF range */
#define FAT16_END (0xFFFF)    /* End of reserved range */

#endif //__FAT16_H_
